<?php include $this->admin_tpl('header'); ?>
<style type="text/css">
#diqu_list li{ color:red}
</style>
<div class="content">
<div class="site"> <?php echo C('site_name')?> <a href="#">联盟商家</a> > 联盟商家添加 </div>
<span class="line_white"></span> 
<script type="text/javascript" src="/template/default/statics/js/area.js"></script> 
<script>var ajaxurl = "<?php echo U('Union/getArea') ?>";</script>
<div class="install mt10">
  <dl>
    <dt><a href="<?php echo U('Agency/index') ?>">代理商列表</a><a href="javascript:void(0)" class="hover">添加代理商</a></dt>
    <dd>
      <div class="install mt10">
        <dl>
          <form action="<?php echo U('Agency/add') ?>" class="addform" method="post">
            <dd>
              <ul class="web">
                <li><strong>区域总代理：</strong>
                   <select name="parent_id" id="parent_id" style="height:30px;">
                    <option value="0" selected>--请选择总代理--</option>
                    <?php
                        foreach($daili as $v){
           			 ?>
                    <option value="<?php echo $v["id"]?>" <?php if($info["parent_id"]==$v["id"]){?> selected="selected"<?php }?>><?php echo $v["realname"]?></option>
                    <?php
						}
					?>
                  </select>
                  <span class="Validform_checktip">请选择总代理名称（非必选）</span> </li>
                <li> <strong>代理商联系人：</strong>
                  <input type="text" class="text_input" name="realname" value="<?php echo $info["realname"];?>" placeholder=''  datatype="*"/>
                  <span class="Validform_checktip">请填写代理商联系人</span> </li>
                <li> <strong>联系电话：</strong>
                  <input type="text" class="text_input" name="phone" value="<?php echo $info["phone"];?>" placeholder='' datatype="*"/>
                  <span class="Validform_checktip">请填写代理商联系电话</span> </li>
                <li> <strong>联系微信：</strong>
                  <input type="text" class="text_input" name="tel" value="<?php echo $info["tel"];?>" placeholder='' />
                  <span class="Validform_checktip">请填写代理商微信</span> </li>
                <li> <strong>联系QQ：</strong>
                  <input type="text" class="text_input" name="qq" value="<?php echo $info["qq"];?>" placeholder='' datatype="*"/>
                  <span class="Validform_checktip">请填写代理商QQ</span> </li>
                <li> <strong>代理商地址：</strong>
                  <select name="province" id="province" onChange="loadArea(this.value, 'city')" style="height:30px;">
                    <option value="-1" selected>--请选择省份--</option>
                    <?php
                        foreach($region as $v){
            ?>
                    <option value="<?php echo $v["area_id"]?>" <?php if($info["province"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
                    <?php
                }
            ?>
                  </select>
                  <select name="city" id="city" onChange="loadArea(this.value, 'district')" style="height:30px;">
                    <option value="-1">--请选择城市--</option>
                    <?php
                       if($opt=="edit"){
            
                        foreach($city as $v){
            ?>
                    <option value="<?php echo $v["area_id"]?>" <?php if($info["city"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
                    <?php
                }
                }
            ?>
                  </select>
                  <select name="district" id="district" onChange="loadArea(this.value, 'null')" style="height:30px;">
                    <option value="-1">--请选择地区--</option>
                    <?php
                       if($opt=="edit"){
            
                        foreach($district as $v){
            ?>
                    <option value="<?php echo $v["area_id"]?>" <?php if($info["district"]==$v["area_id"]){?> selected="selected"<?php }?>><?php echo $v["area_name"]?></option>
                    <?php
                }
                }
            ?>
                  </select>
                </li>
                <li> <strong>代理商详细地址：</strong>
                  <input type="text" class="text_input" name="address" value="<?php echo $info["address"];?>" placeholder=''  datatype="*" />
                  <span class="Validform_checktip">请填写代理商地址</span> </li>
                <li> <strong>负责区域：</strong>
                  <select name="province_qy" id="province_qy" onChange="loadArea(this.value, 'city_qy')" style="height:30px;">
                    <option value="-1" selected>--请选择省份--</option>
                    <?php
                        foreach($region as $v){
            ?>
                    <option value="<?php echo $v["area_id"]?>"><?php echo $v["area_name"]?></option>
                    <?php
            }
            ?>
                  </select>
                  <select name="city_qy" id="city_qy" onChange="loadArea(this.value, 'district_qy')" style="height:30px;">
                    <option value="-1">--请选择城市--</option>
                    <?php
                        foreach($city as $v){
            ?>
                    <option value="<?php echo $v["area_id"]?>"><?php echo $v["area_name"]?></option>
                    <?php
            }
            ?>
                  </select>
                  <select name="district_qy" id="district_qy" onChange="loadArea(this.value, 'null')" style="height:30px;">
                    <option value="-1">--请选择地区--</option>
                    <?php
                        foreach($district as $v){
            ?>
                    <option value="<?php echo $v["area_id"]?>"><?php echo $v["area_name"]?></option>
                    <?php
            }
            ?>
                  </select>
                  <a href="javascript:void(0)" class="add_city">添加</a>
                  <br /><br />
                  <input type="hidden" class="text_input" name="quyu" id="quyu" value="<?php echo $info["quyu"];?>" placeholder=''  datatype="*"/>
                  <ul id="diqu_list"><?php echo $info["quyu_str"];?></ul>
                  <script type="text/javascript">
          
            $(".add_city").click(function(){
            var province=$("#province_qy");
            var city=$("#city_qy");
            var district=$("#district_qy");
            
            if(province.val()=="-1"){
              alert("请选择省份");
              return false;
            }
            if(city.val()=="-1"){
              alert("请选择城市");
              return false;
            }
            var str=province.val()+","+city.val()+","+district.val();
            var text="<li val='"+str+"'>"+province.find("option:selected").text()+","+city.find("option:selected").text()+","+district.find("option:selected").text()+"<a href='javascript:void(0)' class='del_li'>X</a></li>";
            var nowstr=$("#quyu").val();
            var sear=new RegExp(str);
          　　if(sear.test(nowstr))return false;
            $("#diqu_list").append(text);
            if(nowstr==""){
              $("#quyu").val(str);
            }else{
              $("#quyu").val(nowstr+"|"+str)  
            }
          })
          $("body").on('click', ".del_li", function () {
            var vid=$(this).parent().attr("val");
            var all_vid=$("#quyu").val();
            var now_url=all_vid.replace("|"+vid, "");
              now_url=now_url.replace(vid,"");
              $("#quyu").val(now_url);
              $(this).parent().remove();
          });
          
          </script>
                  
                  <span class="Validform_checktip">请填写代理商负责区域</span> </li>
              </ul>
              <div class="edit_box"> <strong class="edit">您正在编辑当前代理商详细信息，默认所见即所得模式，您也可以点击HTML源码切换到代码模式进行编辑。</strong>
                <div class="editor edit"> <?php echo form::editor('content',$info["content"]);?> </div>
              </div>
              <div class="input1">
                <?php if(!empty($info)){ ?>
                <input type="hidden" value="<?php echo $info['id'] ?>" name="id" />
                <input type="hidden" value="edit" name="opt" />
                <?php }else{ ?>
                <input type="hidden" value="add" name="opt" />
                <?php }; ?>
                <input type="button" class="button_search "  id="btn_sub" value="提交" />
              </div>
            </dd>
          </form>
        </dl>
      </div>
    </dd>
  </dl>
</div>
<!--编辑器开始-->
<link rel="stylesheet" type="text/css" href="<?php echo CSS_PATH; ?>Editor/themes/default/default.css">
<script type="text/javascript" src="<?php echo JS_PATH; ?>Editor/kindeditor-min.js"></script> 
<script type="text/javascript" src="<?php echo JS_PATH; ?>Editor/lang/zh_CN.js"></script> 
<script>
        $(function() {
          //编辑器载入
      KindEditor.ready(function(K) {
        //K.create('#content');
        editor = K.editor({
                    uploadJson : '<?php echo U("Admin/Editor/upload?SSID=",'','');?>'+'<?php echo C("SSID");?>',
                  fileManagerJson : '<?php echo U("Admin/Editor/file_manage?parentdir=company_logo/",'','');?>',
                    extraFileUploadParams: {
                         PHPSESSID : '<?php echo session_id() ?>',
                         parentdir : 'company_logo/'
                    },
                    allowFileManager: true
                });
        //给按钮添加click事件
        $('.upimg').live('click', function() {
          var self = $(this);
          editor.loadPlugin('image', function() {
            //图片弹窗的基本参数配置
            editor.plugin.imageDialog({
              imageUrl: self.prev('input').val(), //如果图片路径框内有内容直接赋值于弹出框的图片地址文本框
              //点击弹窗内”确定“按钮所执行的逻辑
              clickFn: function(url, title, width, height, border, align) {
                self.prev("input").val(url);
                self.next("span").html("<img src=" + url + " height=43>");
                editor.hideDialog(); //隐藏弹窗
              }
            });
          });
        });
      });
           
        });
    </script> 
<script>
$(function() {
  var demo = $(".addform").Validform({
    btnSubmit: "#btn_sub",
    btnReset: ".btn_reset",
    tiptype: function(){},
    label: ".label",
    showAllError: false,
    ajaxPost: true,
    callback: function(data) {
      $("#Validform_msg").hide();
      if (data.info == "修改代理商成功") {
        art.dialog({width: 320, time: 5, title: '修改代理商成功', content: data.info,  ok: function(){
       window.location.href = "index.php?m=admin&c=agency&a=index";
    }});
        
      }else if(data.info == "添加代理商成功") {
        art.dialog({width: 320, time: 5, title: '添加代理商成功', content: data.info,  ok: function(){
       window.location.href = "index.php?m=admin&c=agency&a=index";
    }});
      }else{
        art.dialog({width: 320, time: 5, title: '温馨提示(5秒后关闭)', content: data.info, ok: true});
      }
    }
  });
});
</script>
<?php include $this->admin_tpl('copyright') ?>
